package com.tomvian.screens.transitions 
{
	import com.tomvian.screens.AbstractScreen;
	import com.tomvian.screens.AbstractTransition;
	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.Quad;
	import org.libspark.betweenas3.tweens.ITween;
	/**
	 * SlideOutIn
	 * @author Tom Vian
	 */
	public class SlideOutIn extends AbstractTransition
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		protected var _tween:ITween;
		
		protected var _outPos:Object;
		protected var _inPos:Object;
		
		protected var _timeOut:Number;
		protected var _timeIn:Number;
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function SlideOutIn(timeOut:Number = 0.5, timeIn:Number = 0.5, stageWidth:Number = 800.0, toLeft:Boolean = false) 
		{
			_timeOut = timeOut;
			_timeIn = timeIn;
			
			_outPos = { x: toLeft ? -stageWidth : stageWidth};
			_inPos = { x: 0 };
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		override public function play(fromScreen:AbstractScreen, toScreen:AbstractScreen):void 
		{
			super.play(fromScreen, toScreen);
			
			if (_tween) _tween.stop();
			
			_tween = BetweenAS3.serial(	BetweenAS3.tween(_fromScreen.graphic, _outPos, _inPos, _timeOut, Quad.easeInOut),
										BetweenAS3.func(swap), 
										BetweenAS3.tween(_toScreen.graphic, _inPos, _outPos, _timeIn, Quad.easeInOut));
			_tween.onComplete = onTransitionComplete;
			_tween.play();
		}
	}
}